module two {
	export class JewelryInfo extends BaseComponent {
		public constructor() {
			super("JewelryInfo");
		}

		public txt_name_star:eui.Label;
		public txt_title_jewelry:eui.Label;
		public txt_name_jewelry:eui.Label;
		public txt_desc_jewelry:eui.Label;
		
		public list:eui.List;
		public scroller:two.SelectScroller;

		protected created(): void {
			super.created();

			this.scroller.addEventListener(egret.Event.CHANGE, ()=> {
				this.setChooseJew((this.list.dataProvider as eui.ArrayCollection).getItemAt(this.scroller.selectIndex));
			}, this);

			this.scroller.width = GameUtils.getSceneWidth();
		}

		private starId: string;
		private resetPage(): void {
			let starCfg = StarConfig.getConfigById(this.starId);
			this.txt_name_star.text = starCfg.name;

			let allJews = JewelryConfig.getJewelrysByStar(this.starId);

			let ac = this.list.dataProvider as eui.ArrayCollection;
			ac.removeAll();

			for (let i = 0; i < allJews.length; i++) {
				ac.addItem(allJews[i]);
			}
			// this.list.width = GameUtils.getSceneWidth() * allJews.length;

			this.scroller.selectIndex = 0;
			this.setChooseJew(allJews[0])
		}

		public getCurrentJewelryCode():string {
			let ac = this.list.dataProvider as eui.ArrayCollection;
			let cfg:IJewelryConfig = ac.getItemAt(this.scroller.selectIndex);

			return User_getMyJewelryProxy.getInstance().getJewerlyCodeByJewId(cfg.id);
		}

		public getCurrentJewelryId():string {
			let ac = this.list.dataProvider as eui.ArrayCollection;
			let cfg:IJewelryConfig = ac.getItemAt(this.scroller.selectIndex);

			return cfg.id;
		}

		private setChooseJew(cfg: IJewelryConfig):void {
			this.txt_name_jewelry.text = cfg.name;
			this.txt_title_jewelry.text = cfg.title;
			this.txt_desc_jewelry.text = cfg.desc + "";
		}

		public resetStarId(starId:string) {
			this.starId = starId;
			this.resetPage();
		}
	}
}